package dk.mga.androidExplore;

import dk.mga.androidExplore.gpsTracker.GPSTracker;
import dk.mga.androidExplore.sensor.SensorMonitor;
import dk.mga.androidExplore.wifi.WiFiAnalyzer;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.hardware.Sensor;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
/**
 * 
 * @author Allan
 *
 */
public class DeviceExplore extends Activity implements OnClickListener {

	final private String tag = "myLog"; 

	/** Called when the activity is first created. 
	 * Finds and registers listener to each button.
	 * The listener is the DeviceExplore it self.
	 */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.main);
    	View accButton = findViewById(R.id.AccSensor_button);
    	accButton.setOnClickListener(this);
    	View posButton = findViewById(R.id.Button_PosSensor);
    	posButton.setOnClickListener(this);
    	View wifiButton = findViewById(R.id.Button_WiFiLevel);
    	wifiButton.setOnClickListener(this);
    	View gpsButton = findViewById(R.id.Button_gps);
    	gpsButton.setOnClickListener(this);
	    Log.d(tag, "on Create");
    }
    
	@Override
	public void onClick(View v) {
		Log.d(tag, "On click:"+v.getId());
		Intent i;
		switch (v.getId()){
		case R.id.AccSensor_button:
			i = new Intent(this, SensorMonitor.class);
			i.putExtra(SensorMonitor.SENSOR_TYPE, Sensor.TYPE_ACCELEROMETER);
			startActivity(i);
			break;
		case R.id.Button_PosSensor:
			i = new Intent(this, SensorMonitor.class);
			i.putExtra(SensorMonitor.SENSOR_TYPE, Sensor.TYPE_ORIENTATION);
			startActivity(i);
			break;
		case R.id.Button_WiFiLevel:
			i = new Intent(this, WiFiAnalyzer.class);
			startActivity(i);
			break;
		case R.id.Button_gps:
			i = new Intent(this, GPSTracker.class);
			startActivity(i);
			break;
		default:
		}
	}

	/**
	 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	}


	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
	    switch (item.getItemId()) {
	    case R.id.about:
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setMessage(R.string.about_text)
			       .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
			           public void onClick(DialogInterface dialog, int id) {
			                dialog.cancel();
			           }
			       });
			builder.create().show();
	        return true;
	    }
	    return false;
	}
	
	

}